package com.syni.mdd.yhd.common.all.controller.protect;

/**
 * @className BmsBusinessController
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/15 14:25
 * @VERSION 1.0
 **/

import com.syni.mdd.sjb.common.component.utils.common.annotations.CheckParams;
import com.syni.mdd.sjb.common.component.utils.common.annotations.EntranceCheck;
import com.syni.mdd.yhd.common.all.dto.requestDto.coupon.CouponReDto;
import com.syni.mdd.yhd.common.all.service.BmsDxCouponService;
import com.syni.mdd.yhd.common.all.validationGroup.GroupUpdate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/dxCoupon")
public class BmsDxCouponController {
    @Autowired
    BmsDxCouponService bmsDxCouponService;

    @PostMapping("/openCoupon")
    @CheckParams(checkAuth = true,params = {"businessId"})
    public Map<String,Object> openCoupon(@RequestBody Map<String,Object> paramsMap){
        Integer businessId = Integer.parseInt(paramsMap.get("businessId").toString());
        Integer userId = Integer.parseInt(paramsMap.get("userIdentify").toString());
        return bmsDxCouponService.openCoupon(userId,businessId);
    }


    @PostMapping("/userGetBusinessCoupon")
    @CheckParams(params = {"business_id","page_num","page_size"})
    public Map<String,Object> userGetBusinessCoupon(@RequestBody Map<String,Object> paramsMap){
        Integer businessId = Integer.parseInt(paramsMap.get("business_id").toString());
        Integer pageNum = Integer.parseInt(paramsMap.get("page_num").toString());
        Integer pageSize = Integer.parseInt(paramsMap.get("page_size").toString());
        return bmsDxCouponService.findBussinessCoupon(businessId,pageNum,pageSize);
    }

    @PostMapping("/createBusinessCoupon")
    @CheckParams(checkAuth = true,params = {"business_id","pay_type","pay_content"
            ,"use_week","start_time","end_time","use_time","use_scope","holidays_use_status"
            ,"is_share_other"})
    public Map<String,Object> createBusinessCoupon(@RequestBody Map<String,Object> paramsMap){
        return bmsDxCouponService.createBussinessCoupon(paramsMap);
    }


    @PostMapping("/updateBusinessCoupon")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> updateBusinessCoupon(@RequestBody @Validated(GroupUpdate.class) CouponReDto couponReDto){
        return bmsDxCouponService.updateBusinessCoupon(couponReDto);
    }


    @PostMapping("/getBusinessCoupon")
    @CheckParams(checkAuth = true,params = {"business_id","page_num","page_size"})
    public Map<String,Object> getBusinessCoupon(@RequestBody Map<String,Object> paramsMap){
        Integer businessId = Integer.parseInt(paramsMap.get("business_id").toString());
        Integer pageNum = Integer.parseInt(paramsMap.get("page_num").toString());
        Integer pageSize = Integer.parseInt(paramsMap.get("page_size").toString());
        return bmsDxCouponService.findBussinessCoupon(businessId,pageNum,pageSize);
    }

    @PostMapping("/delBusinessCoupon")
    @CheckParams(checkAuth = true,params = {"coupon_id"})
    public Map<String,Object> delBusinessCoupon(@RequestBody Map<String,Object> paramsMap){
        Integer couponId = Integer.parseInt(paramsMap.get("coupon_id").toString());
        return bmsDxCouponService.deleteCoupon(couponId);
    }

}
